﻿@{
    Layout = "";

    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
}
@model ShippingByWeightListModel
@using Nop.Plugin.Shipping.ByWeight.Models;
@using Nop.Web.Framework;
@using Telerik.Web.Mvc.UI;
@using Nop.Core.Infrastructure;
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "shipping-byweight-form" }))
{
    <br />
    <hr />
    <br />
    <table>
        <tr>
            <td class="adminTitle">
                <strong>@T("Plugins.Shipping.ByWeight.Formula"):</strong>
            </td>
            <td class="adminData">
                @T("Plugins.Shipping.ByWeight.Formula.Value")
            </td>
        </tr>
    </table>
    <br />
    <hr />
    <br />
    <table class="adminContent">
        <tr>
            <td>
                @(Html.Telerik().Grid<ShippingByWeightModel>()
                      .Name("shipping-byweight-grid")
                      .DataKeys(keys => keys.Add(x => x.Id).RouteKey("Id"))
                      .Columns(columns =>
                      {
                          columns.Bound(x => x.CountryName).ReadOnly();
                          columns.Bound(x => x.StateProvinceName).ReadOnly();
                          columns.Bound(x => x.Zip);
                          columns.Bound(x => x.ShippingMethodName).ReadOnly();
                          columns.Bound(x => x.DataHtml)
                              .Encoded(false);
                          columns.Bound(x => x.Id)
                              .Width(50)
                              .Centered()
                              .ClientTemplate("<input type='submit' value='" + @T("Admin.Common.Edit").Text + "' onclick=\"" + "javascript:OpenWindow('" + @Url.RouteUrl("Plugin.Shipping.ByWeight.EditPopup") + "?id=<#= Id #>&btnId=btnRefresh&formId=shipping-byweight-form', 800, 400, true); return false;\" class='t-button' />")
                              .Title(T("Admin.Common.Edit").Text);
                          columns.Command(commands =>
                          {
                              commands.Delete().Text(T("Admin.Common.Delete").Text);
                          }).Title(T("Admin.Common.Delete").Text).Width(180);

                      })
                      .DataBinding(dataBinding =>
                      {
                          dataBinding.Ajax()
                              .Select("RatesList", "ShippingByWeight", new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Shipping.ByWeight.Controllers" }, { "area", "" } })
                              .Delete("RateDelete", "ShippingByWeight", new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Shipping.ByWeight.Controllers" }, { "area", "" } });
                      })
                      .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
                      .EnableCustomBinding(true))
            </td>
        </tr>
        <tr>
            <td>
                @{
    var addNewUrl = Url.RouteUrl("Plugin.Shipping.ByWeight.AddPopup") + "?btnId=btnRefresh&formId=shipping-byweight-form";
                }
                <br />
                <input type="submit" id="btnAddNewOption" name="btnAddNewOption" value="@T("Plugins.Shipping.ByWeight.AddRecord")" onclick="javascript:OpenWindow('@(addNewUrl)', 800, 400, true); return false;" class="t-button" />
                <input type="submit" id="btnRefresh" name="btnRefresh" style="display: none" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $('#btnRefresh').click(function () {
                            //refresh grid
                            var optionsGrid = $("#shipping-byweight-grid");
                            optionsGrid.data('tGrid').ajaxRequest();

                            //return false to don't reload a page
                            return false;
                        });                                
                    });
                </script>
            </td>
        </tr>
    </table>
    <br />
    <hr />
    <br />
    <table>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.LimitMethodsToCreated):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.LimitMethodsToCreated)
                @Html.ValidationMessageFor(model => model.LimitMethodsToCreated)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <br/>
                <input type="button" id="savegeneralsettings" class="t-button" value="@T("Admin.Common.Save")" />
                <script type="text/javascript">
                    $(function () {
                        $('#savegeneralsettings').click(function () {
                            $.ajax({
                                cache: false,
                                type: 'POST',
                                url: '@Url.RouteUrl("Plugin.Shipping.ByWeight.SaveGeneralSettings")',
                                data: $(this.form).serialize(),
                                dataType: 'json',
                                success: function (data) {
                                    alert('Saved');
                                },
                                error: function (xhr, ajaxOptions, thrownError) {
                                    alert('Failed to add record.');
                                }
                            });
                            return false;
                        });
                    });
                </script>
            </td>
        </tr>
    </table>
    <br />
    <hr />
    <br />
}